home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_0493.zip / WILD.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-22  |  2KB  |  70 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 271 of 309
  3. From : Peter Beeftink                      1:163/307.25         16 Apr 93  11:37
  4. To   : Ethan Brodsky                       1:121/8.0
  5. Subj : wild cards
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Hello Ethan!
  8.  
  9. Tuesday April 13 1993 15:19, Ethan Brodsky wrote to All:
  10.  
  11.  EB> I am interested in making utilities that accept wildcards I.E.
  12.  EB>                 *.*     ???TP.ZIP    WIN*.EXE
  13.  EB> in Turbo Pascal 6.0.   Does anybody know how to do that?
  14.  
  15. I don't know what you exactly mean by 'accepting' but underneath is my function
  16. wild, which might help you?
  17.  
  18. Peter }
  19.  
  20. Function Wild(flname,card:string):boolean;
  21. {Returns true if the wildcard description in 'card' matches 'flname'
  22. according to DOS wildcard principles.  The 'card' string MUST have a period!
  23. Example: Wild('test.tat','t*.t?t' returns TRUE}
  24.  
  25. var
  26.  c:char;
  27.  p,i,n,l:byte;
  28.  
  29. Begin
  30.   wild:=true;
  31.   {test for special case first}
  32.   if card='*.*' then exit;
  33.   wild:=false;
  34.   p:=pos('.',card);
  35.   i:=pos('.',flname);
  36.   if p=0 then
  37.      Begin
  38.            writeln('Invalid use of function "wild".  Program halted.');
  39.            writeln('Wild card must contain a period.');
  40.            halt;
  41.            End;
  42.   {test the situation before the period}
  43.     n:=1;
  44.     Repeat
  45.     c:=upcase(card[n]);
  46.     if c='*' then n:=p
  47.      else if (upcase(flname[n]) = c) OR (c = '?') then inc(n)
  48.       else exit;
  49.   Until n >= p;
  50.  
  51.     {Now check after the period}
  52.     n:=p+1; {one position past the period of the wild card}
  53.     l:=length(flname);
  54.     inc(i); {one position past the period of the filename}
  55.     repeat
  56.     if n > length(card) then exit;
  57.     c:=upcase(card[n]);
  58.          if c='*' then i:=l+1 {in order to end the loop}
  59.           else
  60.              if (upcase(flname[i]) = c) or (c = '?') then
  61.                 Begin
  62.       inc(n);
  63.       inc(i);
  64.       End
  65.      else exit;
  66.   until i > l;
  67.  
  68.   wild:=true;
  69.  
  70. End;